package best.driver.android.View;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import best.driver.android.Beans.OrderAddresses;
import best.driver.android.Beans.OrderStatus;
import best.driver.android.BestApp;
import best.driver.android.R;
import best.driver.android.Utils.SizeUtils;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by xuefeng on 2014/7/11.
 */
public class SelectPhoneDialog {
    final Context context;
    public Dialog ad;
    ListView listView;
    PhoneAdapter phoneAdapter;


    public SelectPhoneDialog(final Context context, List<OrderAddresses> addresses) {

        this.context = context;
        ad = new Dialog(context, R.style.dialog);
        //ad.requestWindowFeature(Window.FEATURE_NO_TITLE);
        ad.show();
        ad.setCancelable(true);
        //替换对话框窗口的布局
        Window window = ad.getWindow();
        window.setContentView(R.layout.dialog_phone);
        listView = (ListView) window.findViewById(R.id.lv_phones);
        ViewGroup.LayoutParams params = listView.getLayoutParams();
        float density = SizeUtils.getDensity(BestApp.getInstance().getApplicationContext());


        phoneAdapter = new PhoneAdapter(context);
        listView.setAdapter(phoneAdapter);
        List<OrderAddresses> addressesList = new ArrayList<OrderAddresses>();
        for(OrderAddresses address:addresses) {
            if(!TextUtils.isEmpty(address.phone)) {
                addressesList.add(address);
            }
        }
        params.height = (int) (70.5 * density * addressesList.size() - 0.5);
        if(addressesList.size() > 4) {
            params.height = (int) (70.5 * 4.5);
        }
        listView.setLayoutParams(params);
        //mLvMultiUnloadAddress.setPadding(0, (int) (12 * density), 0, (int) (12 * density));
        phoneAdapter.setData(addressesList);

        setCancelOut();
        for(int i = 0; i < addresses.size(); i++) {
            final OrderAddresses address = addresses.get(i);

        }
    }

    public void dismiss() {
        ad.dismiss();
    }

    public void setCancelNotClicked() {
        ad.setCanceledOnTouchOutside(false);
    }

    public void setCancelOut() {
        ad.setCanceledOnTouchOutside(true);
    }
}
